package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.exception.BaseException;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zcf
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
public class ShopController {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //获取营业的状态
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        String shop_status = stringRedisTemplate.opsForValue().get("SHOP_STATUS");
        if (shop_status == null) {
            throw new BaseException(MessageConstant.SHOP_STATUS_ERROR);
        }
        Integer integer = Integer.valueOf(shop_status);
        return Result.success(integer);

    }

    /**
     * 修改店铺营业状态
     */
    @PutMapping("/{status}")
    public Result changeStatus(@PathVariable Integer status) {
        stringRedisTemplate.opsForValue().set("SHOP_STATUS", status.toString());
        return Result.success();
    }
}
